<!-- 就业去向登记 -->
<template>
  <el-card class="mod-ed">
    <div >
      <el-form :readonly="dataForm.id" :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">

      <el-form-item label="去向类型" prop="type">
        <el-select class="select" :disabled="!!dataForm.id" v-model="dataForm.type" placeholder="请选择去向类型">
          <el-option key="2" label="升学" value="升学">
          </el-option>
          <el-option key="3" label="就业" value="就业">
          </el-option>
          <el-option key="4" label="待定" value="待定">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="去向" prop="destination">

        <el-input :readonly="!!dataForm.id" type="textarea" v-model="dataForm.destination" placeholder="去向"></el-input>
      </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
      </span>
    </div>
  </el-card>

  </template>

  <script>
import { employmentDestinationApi } from '@/api/student'

    export default {
      data () {
        return {
          visible: false,
          dataForm: {
            id: 0,
            studentId: '',
            type: '',
            destination: ''
          },
          dataRule: {

            type: [
              { required: true, message: '去向类型不能为空', trigger: 'blur' }
            ],
            destination: [
              { required: true, message: '去向不能为空', trigger: 'blur' }
            ]
          }
        }
      },
      mounted () {
        this.init()
      },

      methods: {
        init () {
            this.$refs['dataForm'].resetFields()
              employmentDestinationApi.getUsered()
              .then(({ed}) => {
                console.log(ed);
                  this.dataForm = ed
              }).catch(err=>{
                console.log(err);
              })

        },
        // 表单提交
        dataFormSubmit () {
          this.$refs['dataForm'].validate((valid) => {
            if (valid) {
              employmentDestinationApi.saveed(this.dataForm)
              .then(data=>{
                if (data && data.code == 20000) {
                  this.$message({
                    message: '操作成功',
                    type: 'success',
                    duration: 1500,
                    onClose: () => {
                      this.visible = false
                      this.$emit('refreshDataList')
                    }
                  })
                } else {
                  this.$message.error(data.message)
                }
              })
            }
          })
        }
      }
    }
  </script>
  <style lang="scss">

.mod-ed{
  max-width: 800px;
  min-width: 300px;
  margin: auto;

  .select{
    width:100%
  }
}
</style>
